#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include<pthread.h>

struct ClientData
{
    /* data */
    struct sockaddr_in server;
    int PORT;
    char *AddressIP;
    int client_fd;
}ClientDataStruct;

int main(int argc,char **argv){
    ClientDataStruct.client_fd=socket(PF_INET,SOCK_STREAM,0);
    if( ClientDataStruct.client_fd==-1){
        perror("socket error");
        exit(-1);
    }
    memset(&ClientDataStruct.server,'\0',sizeof(ClientDataStruct.server));
    ClientDataStruct.AddressIP=argv[1];
    ClientDataStruct.PORT=atoi(argv[2]);

    ClientDataStruct.server.sin_family=AF_INET;
    ClientDataStruct.server.sin_addr.s_addr=inet_addr(ClientDataStruct.AddressIP);
    ClientDataStruct.server.sin_port=htons(ClientDataStruct.PORT);

    if(connect(ClientDataStruct.client_fd,(struct sockaddr*)(&ClientDataStruct.server),sizeof(struct sockaddr))<0){
        perror("connect error");
        exit(-1);     
    }
    
    while (1){
        /* code */
        char buf[100]={'\0'};
        printf("client input:\n");
        fgets(buf,100,stdin);
        if(send(ClientDataStruct.client_fd,buf,100,0)<0){
            perror("send error");
            exit(-1);
        }
    }
    
    return 0;
}